package Windows.Tree;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.tree.TreeCellRenderer;

import GroupWare.ShareFile;

public class PicTreeCellRenderer extends JLabel implements TreeCellRenderer {
	protected Color selectedBackground;
	protected Color selectedForeground;
	protected Color noselectedBackground;
	protected Color noselectedForeground;
	protected Border lb;

	public PicTreeCellRenderer() {
		super();
		this.lb = LineBorder.createBlackLineBorder();
		this.selectedBackground = Color.green;
		this.selectedForeground = Color.blue;
		this.noselectedBackground = Color.white;
		this.noselectedForeground = Color.black;
		this.setForeground(this.noselectedForeground);
		this.setBackground(this.noselectedBackground);
		this.setFont(new Font("Default", Font.PLAIN, 12));

	}

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		// TODO Auto-generated method stub
		this.setText(value.toString());
		if (value instanceof TreeNodePic) {
			TreeNodePic node = (TreeNodePic) value;
			setIcon(node.getIcon());
		}
		if (value instanceof ShareFile) {
			ShareFile node = (ShareFile) value;
			setIcon(node.getIcon());
		}
		if (selected) {
			this.setForeground(this.selectedForeground);
			this.setBackground(this.selectedBackground);
//			this.setSize(this.getWidth()+6, this.getHeight());
//			this.setBorder(lb);
		} else {
			this.setBackground(this.noselectedBackground);
			this.setForeground(this.noselectedForeground);
//			this.setSize(this.getWidth()-6, this.getHeight());
//			this.setBorder(null);
		}
		return this;
	}
}
